/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FPForm.java
 *
 * Created on 20.02.2012., 18.30.32
 */
package gui.forms;

import base.saveTemplate.SaveStatus;
import base.saveTemplate.UpdateStatus;
import gui.forms.coordinator.FormCoordinator;
import gui.panels.PanelHome;
import gui.panels.PanelMessages;
import gui.panels.PanelProfil;
import gui.panels.PanelStatus;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import model.controller.ControllerFPUser;

/**
 *
 * @author Jelena
 */
public class FPForm extends javax.swing.JFrame {

    /** Creates new form FPForm */
    public FPForm() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jMenuBar1 = new javax.swing.JMenuBar();
        menuHome = new javax.swing.JMenu();
        miStatusi = new javax.swing.JMenuItem();
        miSviStatusi = new javax.swing.JMenuItem();
        miMessages = new javax.swing.JMenuItem();
        menuProfile = new javax.swing.JMenu();
        miProfile = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
        getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

        menuHome.setText("Početna");

        miStatusi.setText("Statusi");
        miStatusi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miStatusiActionPerformed(evt);
            }
        });
        menuHome.add(miStatusi);

        miSviStatusi.setText("Svi statusi");
        miSviStatusi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miSviStatusiActionPerformed(evt);
            }
        });
        menuHome.add(miSviStatusi);

        miMessages.setText(" Poruke");
        miMessages.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miMessagesActionPerformed(evt);
            }
        });
        menuHome.add(miMessages);

        jMenuBar1.add(menuHome);

        menuProfile.setText(" Profil");
        menuProfile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuProfileActionPerformed(evt);
            }
        });

        miProfile.setText("Tvoj profil");
        miProfile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miProfileActionPerformed(evt);
            }
        });
        menuProfile.add(miProfile);

        jMenuBar1.add(menuProfile);

        setJMenuBar(jMenuBar1);

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
    FormCoordinator.getInstance().setNewPanel(new PanelHome());
}//GEN-LAST:event_formWindowOpened

private void menuProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuProfileActionPerformed
        try {
            ControllerFPUser.getInstance().forbidAccess();
            FormCoordinator.getInstance().setNewPanel(new PanelProfil());
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
}//GEN-LAST:event_menuProfileActionPerformed

private void miMessagesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miMessagesActionPerformed
    
     try {
            ControllerFPUser.getInstance().forbidAccess();
            FormCoordinator.getInstance().setNewPanel(new PanelMessages());
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
}//GEN-LAST:event_miMessagesActionPerformed

private void miProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miProfileActionPerformed
   try {
            ControllerFPUser.getInstance().forbidAccess();
            FormCoordinator.getInstance().setNewPanel(new PanelProfil());
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
}//GEN-LAST:event_miProfileActionPerformed

private void miStatusiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miStatusiActionPerformed
     try {
            ControllerFPUser.getInstance().forbidAccess();
            FormCoordinator.getInstance().setNewPanel(new PanelStatus());
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
}//GEN-LAST:event_miStatusiActionPerformed

private void miSviStatusiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miSviStatusiActionPerformed
     try {
            ControllerFPUser.getInstance().forbidAccess();
            FormAllStatuses fas= new FormAllStatuses();
            SaveStatus.attach(fas);
            UpdateStatus.attach(fas);
            fas.setVisible(true);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    
    
}//GEN-LAST:event_miSviStatusiActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FPForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FPForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FPForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FPForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new FPForm().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JMenu menuHome;
    private javax.swing.JMenu menuProfile;
    private javax.swing.JMenuItem miMessages;
    private javax.swing.JMenuItem miProfile;
    private javax.swing.JMenuItem miStatusi;
    private javax.swing.JMenuItem miSviStatusi;
    // End of variables declaration//GEN-END:variables
    private JPanel activePanel;
    
    public void setActivePanel(JPanel newPanel){
        if (activePanel!=null) this.remove(activePanel);

        activePanel = newPanel;
        getContentPane().add(activePanel,java.awt.BorderLayout.SOUTH); 
        activePanel.setVisible(true);
        validate();
        repaint();
        pack();
    }


}
